[XM] Add commands to implement lifecycle commands via the XM XMLRPC interface.
authorAlastair Tse <atse@xensource.com>
Thu, 5 Oct 2006 16:29:19 +0000 (17:29 +0100)
committerAlastair Tse <atse@xensource.com>
Thu, 5 Oct 2006 16:29:19 +0000 (17:29 +0100)
Signed-off-by: Alastair Tse <atse@xensource.com>
tools/python/xen/xm/create.py
tools/python/xen/xm/main.py

index a6374de7de91d779b5a0efe1249cf742329b4a1a..21cb03817e7c4c7a16f688b9ea73b9ce18916324 100644 (file)
@@ -439,6 +439,21 @@ gopts.var('uuid', val='',
           addresses for virtual network interfaces.  This must be a unique 
           value across the entire cluster.""")
 
+gopts.var('autostart', val='no|yes',
+          fn=set_bool, default=0,
+          use="Should the start VM automatically when Xend starts.")
+
+gopts.var('autostop', val='no|yes',
+          fn=set_bool, default=0,
+          use="Should stop VM automatically when Xend stops.")
+
+gopts.var('on_xend_stop', val='shtudown|suspend',
+          fn=set_value, default="shutdown",
+          use="""Behaviour when Xend stops and autostop is on:
+          - shutdown:       Domain is shutdown;
+          - suspend:        Domain is suspended;
+          """)
+
 def err(msg):
     """Print an error to stderr and exit.
     """
@@ -668,8 +683,9 @@ def make_config(vals):
                 config.append([n, v])
 
     map(add_conf, ['name', 'memory', 'maxmem', 'shadow_memory',
-                   'restart', 'on_poweroff', 'on_reboot', 'on_crash',
-                   'vcpus', 'features'])
+                   'restart', 'on_poweroff',
+                   'on_reboot', 'on_crash', 'vcpus', 'features',
+                   'autostart', 'autostop', 'on_xend_stop'])
 
     if vals.uuid is not None:
         config.append(['uuid', vals.uuid])
index 19126e72714ed45f2f01cadc2a2488e3a1afd775..d251dfec999589ea57bb788153c0254e90791583 100644 (file)
@@ -92,6 +92,15 @@ SUBCOMMAND_HELP = {
     'unpause'     : ('<Domain>', 'Unpause a paused domain.'),
     'uptime'      : ('[-s] <Domain>', 'Print uptime for a domain.'),
 
+    # Life cycle xm commands
+    'new'         : ('<ConfigFile> [options] [vars]',
+                     'Adds a domain to Xend domain management'),
+    'delete'      : ('<DomainName>',
+                     'Remove a domain from Xend domain management.'),
+    'start'       : ('<DomainName>', 'Start a Xend managed domain'),
+    'resume'      : ('<DomainName>', 'Resume a Xend managed domain'),
+    'suspend'     : ('<DomainName>', 'Suspend a Xend maanged domain'),
+
     # less used commands
 
     'dmesg'       : ('[-c|--clear]',
@@ -194,6 +203,8 @@ SUBCOMMAND_OPTIONS = {
 common_commands = [
     "console",
     "create",
+    "new",
+    "delete",
     "destroy",
     "dump-core",
     "help",
@@ -203,8 +214,11 @@ common_commands = [
     "pause",
     "reboot",
     "restore",
+    "resume",
     "save",
     "shutdown",
+    "start",
+    "suspend",
     "top",
     "unpause",
     "uptime",
@@ -214,6 +228,8 @@ common_commands = [
 domain_commands = [
     "console",
     "create",
+    "new",
+    "delete",
     "destroy",
     "domid",
     "domname",
@@ -226,8 +242,11 @@ domain_commands = [
     "reboot",
     "rename",
     "restore",
+    "resume",
     "save",
     "shutdown",
+    "start",
+    "suspend",
     "sysrq",
     "top",
     "unpause",
@@ -678,6 +697,26 @@ def xm_vcpu_list(args):
 
             print format % locals()
 
+def xm_start(args):
+    arg_check(args, "start", 1)
+    dom = args[0]
+    server.xend.domain.start(dom)
+
+def xm_delete(args):
+    arg_check(args, "delete", 1)
+    dom = args[0]
+    server.xend.domain.delete(dom)
+
+def xm_suspend(args):
+    arg_check(args, "suspend", 1)
+    dom = args[0]
+    server.xend.domain.suspend(dom)
+
+def xm_resume(args):
+    arg_check(args, "resume", 1)
+    dom = args[0]
+    server.xend.domain.resume(dom)
+    
 def xm_reboot(args):
     arg_check(args, "reboot", 1, 3)
     from xen.xm import shutdown
@@ -1318,6 +1357,7 @@ commands = {
     # xenstat commands
     "top": xm_top,
     # domain commands
+    "delete": xm_delete,
     "destroy": xm_destroy,
     "domid": xm_domid,
     "domname": xm_domname,
@@ -1327,8 +1367,10 @@ commands = {
     "restore": xm_restore,
     "save": xm_save,
     "shutdown": xm_shutdown,
+    "start": xm_start,
     "sysrq": xm_sysrq,
     "uptime": xm_uptime,
+    "suspend": xm_suspend,
     "list": xm_list,
     # memory commands
     "mem-max": xm_mem_max,
@@ -1368,13 +1410,14 @@ commands = {
 ## The commands supported by a separate argument parser in xend.xm.
 IMPORTED_COMMANDS = [
     'create',
+    'new',    
     'migrate',
     'labels',
-    'addlabel',
     'cfgbootpolicy',
     'makepolicy',
     'loadpolicy',
-    'dumppolicy',
+    'dumppolicy',        
+    'addlabel',
     'rmlabel',
     'getlabel',
     'dry-run',